package com.sk.util;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

import javax.sql.rowset.spi.XmlWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

/**
 * 用于修改 pom。xml
 * @Author jiaok
 * @Date 2023-11-30 16:18
 */
public class XmlUtil {

    public static void updateFramePomXml(String path ,String val) throws  IOException, DocumentException {

        //准备修改xml
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(path);
        //获取根元素
        Element rootElement = document.getRootElement();
        rootElement.element("artifactId").setText(val);
        rootElement.element("name").setText(val);
        rootElement.element("build").element("finalName").setText(val);

        FileOutputStream fileOutputStream = new FileOutputStream(path);
        //创建输出格式
        OutputFormat outputFormat = OutputFormat.createPrettyPrint();
        outputFormat.setEncoding("utf-8");
        XMLWriter xmlWriter = new XMLWriter(fileOutputStream, outputFormat);
        xmlWriter.write(document);
        xmlWriter.flush();
        xmlWriter.close();
    }



}
